/**
 *  Copyright (c) 1997-2013, www.tinygroup.org (luo_guo@icloud.com).
 *
 *  Licensed under the GPL, Version 3.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.gnu.org/licenses/gpl.html
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.tinygroup.dbf;

import java.io.File;
import java.io.IOException;
import java.text.ParseException;

/**
 * Dbf解析器
 * Created by luoguo on 2014/4/26.
 */
public interface DbfReader {
    int HEADER_LENGTH = 32;
    int HEADER_END_CHAR = 13;
    int FIELD_LENGTH = 32;
    int NAME_LENGTH = 11;
    int RECORD_COUNT_POSITION = 3;
    int RECORD_COUNT_LENGTH = 4;
    int HEADER_LENGTH_POSITION = 7;
    int HEADER_LENGTH_LENGTH = 2;
    int RECORD_LENGTH_POSITION = 9;
    int RECORD_LENGTH_LENGTH = 2;
    int FIELD_LENGTH_POSITON = 16;
    int FIELD_DECIMAL_POSITON = 17;
    int DISPLACEMENT_POSITION = 12;
    int DISPLACEMENT_LENGTH = 4;
    int FIELD_FLAG_POSITION = 18;
    int START_YEAR = 1900;
    int YEAR_POS = 10000;
    int MONTH_POS = 100;

    /**
     * 返回一个DbfDocument
     *
     * @param fileName
     * @param encode
     * @return
     */
    DbfDocument readDbf(String fileName, String encode) throws IOException, ParseException;

    DbfDocument readDbf(File file, String encode) throws IOException, ParseException;

    /**
     * 之所以这里有这个方法，是因为有时候采用流式读入的时候，需要手工关闭，对于非流式读入的，可以在readDbf中，就关闭文件，而在这里空实现即可
     *
     * @throws IOException
     */
    void close() throws IOException;

}
